package com.vogtec.fota.quartz;

import com.vogtec.fota.mqtt.ApplicationContextProvider;
import com.vogtec.fota.service.UpgradeTaskService;
import com.vogtec.fota.service.impl.UpgradeTaskServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by wei on 2017/7/24.
 */
@Slf4j
@Component
public class FinishJob implements Job{

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        log.info("***** in quartz.FinishJob *****");

        Integer id = Integer.valueOf(jobExecutionContext.getJobDetail().getJobDataMap().getString("id"));
        log.info(" the id to finish : [{}] ",id);
        UpgradeTaskServiceImpl upgradeTaskServiceImpl = ApplicationContextProvider.getBean(
                "upgradeTaskServiceImpl",UpgradeTaskServiceImpl.class);
        upgradeTaskServiceImpl.finishTask(id);

    }
}
